// example.pov -- Sample scene file demonstrating some of the features of the
//                POV-QLab package
//
// There are a LOT of options to POV-QLab which can be tweaked to really show
// off some of the features presented here.  For more information, please see
// the POV-QLab docs, but here are a few suggested things to try:
//
// Default view:
//   povray example.pov
//
// "Finished" view:
//   povray example.pov Declare=QLAB_SHOW_LAB=0
//
// Different cameras/viewpoints:
//   povray example.pov Declare=QLAB_STD_CAMERA=n
//      (where -11 <= n <= 11)
//   povray example.pov Declare=QLAB_CAMERA_DISTANCE=8
//   povray example.pov Declare=QLAB_ORTHO_TOP=4
//     (also QLAB_ORTHO_FRONT, QLAB_ORTHO_RIGHT, and try "-4" instead of "4")
//   povray example.pov Declare=QLAB_ORTHO_CAM=1
//
// Changing what Lab elements are displayed:
//   povray example.pov Declare=QLAB_GRID_XZ=0 Declare=QLAB_GRID_XY=1
//   povray example.pov Declare=QLAB_SHOW_HUD=0
//   povray example.pov Declare=QLAB_SHOW_NOTES=0
//   povray example.pov Declare=QLAB_SHOW_LABELS=0
//   povray example.pov Declare=QLAB_SHOW_ARROWS=0
//
// Misc other stuff:
//   povray example.pov Declare=QLAB_SCALE=0.5
//   povray example.pov Declare=QLAB_GRID_SPACING=2
//   povray example.pov Declare=QLAB_GRID_SPACING_MINOR=0

#version 3.7;

#include "qlab.inc"
#include "colors.inc"

// Declare any QLab settings we want before we start...
#declare QLAB_CAMERA_LOOK_AT = <0, 0.25, 0>;

// The following makes reflective textures (i.e. M_Copper) look less washed-out
// by our gray background color:
#declare QLAB_BACKGROUND_REFLECTION = rgb 0;

// Make sure we call QLabSetup() first before using any other QLab* macros!
QLabSetup()

// Put an annotation at the bottom of our image
QLabHUDLabel(<0, -1>, "Fig 1: Electrical Current in a Wire", Black, <0, 2>)

// A semi-realistic "copper wire" material.
// (I really wish POV-Ray's stock metal textures weren't quite so horrible.
// We shouldn't have to do this sort of thing ourselves..)
#declare M_Copper = material {
  texture {
    pigment { rgb <0.7, 0.4, 0.2> }
    finish {
      ambient 0
      diffuse 0.2
      specular 0.5
      metallic
      brilliance 5
      roughness 0.02
      reflection { 0.5 metallic }
    }
  }
}

// A representation of an "electron".  (Note: Due to the use of QLabLabel, the
// minus-sign inside the sphere will automatically orient itself to the camera
// position, no matter where it is)
#declare Electron = union {
  sphere {
    0, 0.075
    pigment { rgbt <0.2, 0.2, 0.2, 0.8> }
    finish { diffuse 0.5 ambient 0 specular 0.25 roughness 0.3 }
  }
  QLabLabel(0, "-", Black, 0, true)
}

// This is our "wire"
cylinder {
  <-1.75, 0, 0>, <1.75, 0, 0>, 0.25
  material { M_Copper }
}

// Current arrow
QLabArrow(<-1, 1, 0>, <1, 1, 0>, Blue)

// Magnetic field lines
#for (X, -1, 1, 0.25)
  // QLabCurvedArrow can actually draw a curving arrow from any point to any
  // other point, but if we put the start and end points very close together,
  // it can actually be used to draw a fully circular arrow too.
  QLabCurvedArrow(<X, 0, -0.5>, <X, 0, 0.5>, <X, 0.001, -0.5>, Green)
#end

// Electron flow arrow
#declare QLAB_ARROW_SCALE = 0.5;
#declare Electron_String = union {
  #for (X, -0.75, 0.75, 0.25)
    object { Electron translate <X, 0.85, 0> }
  #end
}
Electron_String
difference {
  // Arrows can be used in CSG too :)
  QLabArrow(<1, 0.85, 0>, <-1, 0.85, 0>, Red)
  Electron_String
}

// Label everything
QLabLabel(<0, 1.2, 0>, "Electrical Current", Blue, <0, 1>, false)
QLabLabel(<0, -1, 0>, "Magnetic", Green * 0.5, <0, 1.1>, false)
QLabLabel(<0, -1, 0>, "Field", Green * 0.5, <0, -1.1>, false)

#declare QLAB_LABEL_SCALE = 0.5;
QLabLabel(<0, 0.75, 0>, "(electron flow)", Red, <0, -1>, false)

#declare QLAB_LABEL_SCALE = 1.5;
QLabLabel(<-2.2, 0, 0>, "+V", Black, <0, 0, 0>, false)
QLabLabel(<2.1, 0, 0>, "-V", Black, <0, 0, 0>, false)

// This is an example of an annotation only displayed when in full Lab view
// (i.e. when QLAB_SHOW_LAB=true and QLAB_SHOW_HUD=true)
#declare QLAB_LABEL_ARROW_ANCHOR = <0, -1>;
QLabHUDNotePointer(<-1, 0.7>, "(electrons not actual size!)", Red * 0.5, <1, 0>, <-0.75, 0.85, 0>)
